package com.hpinto.generadordefrcuencias;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.NumberPicker;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity {


    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment())
                    .commit();
        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container, false);

            NumberPicker np1 = (NumberPicker) rootView.findViewById(R.id.numberPicker1);
            np1.setMaxValue(20000);
            np1.setMinValue(1);
            np1.setValue(19000);

            NumberPicker np2 = (NumberPicker) rootView.findViewById(R.id.numberPicker2);
            np2.setMaxValue(100);
            np2.setMinValue(0);
            np2.setValue(50);

            final Button btn1 = (Button) rootView.findViewById(R.id.button1);
            btn1.setOnClickListener(new OnClickListener() {
              public void onClick(View v) {
                final String caption = btn1.getText().toString();
                if (caption.equals(getResources().getString(R.string.StrPlay))){
                  btn1.setText(getResources().getString(R.string.StrStop));
                } else if (caption.equals(getResources().getString(R.string.StrStop))){
                  btn1.setText(getResources().getString(R.string.StrPlay));
                }
                Toast msg = Toast.makeText(v.getContext(), caption+" de la reproducción", Toast.LENGTH_SHORT);
                msg.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
                msg.show();
              }
            });

            return rootView;
        }
    }

}
